using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BookInfoCS
{
[Designer(typeof(BookInfoDesigner))]
[ControlBuilder(typeof(BookBuilder))]
[ParseChildren(false)]
[ToolboxData("<{0}:BookInfo runat=server></{0}:BookInfo>")]
public class BookInfo : System.Web.UI.WebControls.WebControl
{
 private string _MainTitle;
 private string _SubTitle;
 private System.Collections.ArrayList _Authors = new System.Collections.ArrayList();
 private System.Collections.ArrayList _ChildControls;


 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
 [NotifyParentProperty(true)]
 [PersistenceMode(PersistenceMode.InnerProperty)]
 public string MainTitle
 {
   get
   {
       return _MainTitle;
   }
     set
   {
        _MainTitle = value;
   }
 }

 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
 [NotifyParentProperty(true)]
 [PersistenceMode(PersistenceMode.InnerProperty)]
 public string SubTitle
 {
    get
   {
       return _SubTitle;
   }
     set
   {
        _SubTitle = value;
   }
  }
    public System.Collections.ArrayList Authors
    {
        get
        {
            return _Authors;
        }
        set
        {
            _Authors = value;
        }
    }

    private string _Description;

    public string Description
    {
        get
        {
            return _Description;
        }
        set
        {
            _Description = value;
        }
    }

   public System.Collections.ArrayList ChildControls
    {
        get
        {
            return _ChildControls;
        }
        set
        {
            _ChildControls = value;
        }
    }

    protected override void AddParsedSubObject(object obj)
    {
        if (obj is Author)
        {
            if (_Authors == null)
            {
                _Authors = new System.Collections.ArrayList(2);
            }
            this.Authors.Add(obj);
        }

        if (obj is Titles)
        {
            this.MainTitle = ((Titles)obj).Main;
            this.SubTitle = ((Titles)obj).SubTitle;
        }

        if (obj is Description)
        {
            Description ds;
            ds = (Description)obj;
            this.Description = ds.Text;
        }

        if (obj is LiteralControl)
        {
            this.Controls.Add((System.Web.UI.WebControls.WebControl) obj );
        }

        if (obj is Label)
        {
            this.Controls.Add((System.Web.UI.WebControls.WebControl) obj);
        }
    }

    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
        writer.Write("<Table>");

        foreach (Author aut in this.Authors)
        {
            writer.Write("<tr>");
            writer.Write("<tc>" + aut.FirstName + "</tc>");
            writer.Write("<tc>" + aut.LastName + "</tc>");
            writer.Write("</tr>");
        }

        writer.Write("</Table>");
    }
 }
    public class Author
    {
        private string _FirstName;
        private string _LastName;

        public string FirstName
        {
            get
            {
                return _FirstName;
            }
            set
            {
                _FirstName = value;
            }
        }
        public string LastName
        {
            get
            {
                return _LastName;
            }
            set
            {
                _LastName = value;
            }
        }
    }

    public class Titles
    {
     private string _MainTitle;
     private string _SubTitle;

        public string Main
        {
            get
            {
                return _MainTitle;
            }
            set
            {
                _MainTitle = value;
            }
        }
     public string SubTitle
     {
      get
      {
       return _SubTitle;
      }
      set
      {
       _SubTitle = value;
      }
     }
   }
    public class Description : System.Web.UI.WebControls.Literal
    { }

 }


